package cc.langk.sms.handler;

import cc.langk.sms.entity.AliSmsHistory;
import cc.langk.sms.entity.TencentSmsHistory;
import cc.langk.sms.entity.TencentSmsResult;
import cc.langk.sms.util.tencent.SmsMultiSender;
import cc.langk.sms.util.tencent.SmsSingleSender;
import cc.langk.sms.util.tencent.SmsSingleSenderResult;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class TencentHandler {

    private SmsSingleSender smsSingleSender;
    private SmsMultiSender smsMultiSender;

    @PostConstruct
    public void init() {
        try {
            smsSingleSender = new SmsSingleSender(1400057215, "00aed7390b3cbb25f52f1dd224f77597 ");
            smsMultiSender = new SmsMultiSender(1400057215, "00aed7390b3cbb25f52f1dd224f77597 ");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public TencentSmsHistory sendSingleSms(TencentSmsHistory smsHistory) {
        try {
            if (smsSingleSender != null) {
                SmsSingleSenderResult re =  smsSingleSender.send(1, "86", smsHistory.getMobile(), "尊敬的用户，欢迎您使用易红包。", null, null);
                if (re!=null){
                    TencentSmsResult tencentSmsResult = new TencentSmsResult();
                    tencentSmsResult.setSmsSingleSenderResult(re);
                    smsHistory.setResult(tencentSmsResult);
                    return smsHistory;
                }else {
                    smsHistory.makeErrorResult();
                    return smsHistory;
                }
            }
            smsHistory.makeErrorResult();
            return smsHistory;
        } catch (Exception e) {
            e.printStackTrace();
            smsHistory.makeErrorResult();
            return smsHistory;
        }

    }

}
